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

import com.pig4cloud.pigx.app.api.entity.as.AsPlatformType;
import com.pig4cloud.pigx.app.service.as.AsPlatformTypeService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
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("/asPlatformType")
@Tag(description = "AS-platformType-manage", name = "AS-平台类型")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AsPlatformTypeController {

	private final AsPlatformTypeService asPlatformTypeService;

	/**
	 * 新增订阅计划
	 * @param asPlatformType 订阅计划
	 * @return success/false
	 */
	@SysLog("新增平台类型")
	@Operation(summary = "新增平台类型", description = "新增平台类型")
	@PostMapping("/save")
//	@PreAuthorize("@pms.hasPermission('as_subplan_add')")
	public R save(@Valid @RequestBody AsPlatformType asPlatformType) {
		asPlatformTypeService.save(asPlatformType);
		return R.ok();
	}

	/**
	 * 返回平台类型集合
	 * @param platType 平台类型
	 * @return 平台类型集合
	 * get -> post
	 */
	@Inner(value = false)
	@Operation(summary = "查询平台类型", description = "查询平台类型 0：全部")
	@GetMapping("/getPlatformType")
	public R getPlatformType(Integer platType) {
		return R.ok(asPlatformTypeService.listAsPlatformTypeByType(platType));
	}

	/**
	 * 更新平台类型
	 * @param asPlatformType
	 * @return
	 */
	@SysLog("更新平台类型")
	@Operation(summary = "更新平台类型", description = "更新平台类型")
	@PutMapping("/update")
	public R update(@Valid @RequestBody AsPlatformType asPlatformType) {
		return R.ok(asPlatformTypeService.updateById(asPlatformType));
	}

}
