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

import com.pig4cloud.pigx.app.api.entity.as.AsPlatform;
import com.pig4cloud.pigx.app.service.as.AsPlatformService;
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("/asPlatform")
@Tag(description = "AS platform manage", name = "AS-流媒体平台")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AsPlatformController {

	private final AsPlatformService asPlatformService;

	/**
	 * 新增媒体平台
	 * @param asPlatform 媒体平台
	 * @return success/false
	 */
	@Operation(summary = "新增媒体平台", description = "新增媒体平台")
	@PostMapping("/save")
	public R save(@Valid @RequestBody AsPlatform asPlatform) {
		asPlatformService.save(asPlatform);
		return R.ok();
	}

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

	/**
	 * 更新媒体平台
	 * @param asPlatform
	 * @return
	 */
	@SysLog("更新媒体平台")
	@Operation(summary = "更新媒体平台", description = "更新媒体平台")
	@PutMapping("/update")
	public R update(@Valid @RequestBody AsPlatform asPlatform) {
		return R.ok(asPlatformService.updateById(asPlatform));
	}

}
