package com.pig4cloud.pigx.app.controller.as;

import com.pig4cloud.pigx.app.api.entity.as.AsSubPlan;
import com.pig4cloud.pigx.app.service.as.AsSubPlanService;
import com.pig4cloud.pigx.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * as 订阅计划表
 *
 * @author amigo
 * @date 2023-7
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/asSubPlan")
@Tag(description = "AS-subPlan-manage", name = "AS-流媒体订阅计划")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AsSubPlanController {

	private final AsSubPlanService asSubPlanService;

	/**
	 * 新增订阅计划
	 * @param subPlan 订阅计划
	 * @return success/false
	 */
	@Operation(summary = "新增订阅计划", description = "新增订阅计划")
	@PostMapping("/save")
//	@PreAuthorize("@pms.hasPermission('as_subplan_add')")
	public R save(@Valid @RequestBody AsSubPlan subPlan) {
		asSubPlanService.save(subPlan);
		return R.ok();
	}

	/**
	 * 返回订阅计划集合
	 * @param platId 平台id
	 * @return 订阅计划集合
	 */
	@Operation(summary = "获取订阅计划", description = "获取订阅计划")
	@GetMapping("/getSubPlan")
	public R getSubPlan(Long platId) {
		return R.ok(asSubPlanService.listSubPlanByPlatId(platId));
	}

	/**
	 * 更新订阅计划
	 * @param subPlan
	 * @return
	 */
	@Operation(summary = "更新订阅计划", description = "更新订阅计划")
	@PutMapping("/update")
	public R update(@Valid @RequestBody AsSubPlan subPlan) {
		return R.ok(asSubPlanService.updateById(subPlan));
	}

}
