package com.moka.gdtauto.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moka.gdtauto.annotation.AuthUser;
import com.moka.gdtauto.common.Result;
import com.moka.gdtauto.entity.AssetDramaSyncConf;
import com.moka.gdtauto.entity.SysUser;
import com.moka.gdtauto.service.AssetDramaSyncConfService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * 短剧资产同步配置控制器
 *
 * @author moka
 * @since 2026-03-04
 */
@Tag(name = "短剧资产同步配置", description = "短剧资产同步配置CRUD")
@Slf4j
@RestController
@RequestMapping("/api/gdt/asset/drama/sync/conf")
@RequiredArgsConstructor
public class AssetDramaSyncConfController {

    private final AssetDramaSyncConfService assetDramaSyncConfService;

    /**
     * 新增
     */
    @Operation(summary = "新增短剧资产同步配置")
    @PostMapping("/add")
    public Result<Void> add(@RequestBody AssetDramaSyncConf conf, @AuthUser SysUser user) {
        try {
            conf.setJobNumber(user.getJobNumber());
            boolean success = assetDramaSyncConfService.addConf(conf);
            return success ? Result.success("新增成功") : Result.fail("新增失败");
        } catch (Exception e) {
            log.error("新增短剧资产同步配置失败", e);
            return Result.fail("新增失败：" + e.getMessage());
        }
    }

    /**
     * 删除
     */
    @Operation(summary = "删除短剧资产同步配置")
    @PostMapping("/delete")
    public Result<Void> delete(@RequestParam Long id) {
        try {
            boolean success = assetDramaSyncConfService.deleteConf(id);
            return success ? Result.success("删除成功") : Result.fail("删除失败");
        } catch (Exception e) {
            log.error("删除短剧资产同步配置失败，id={}", id, e);
            return Result.fail("删除失败：" + e.getMessage());
        }
    }

    @GetMapping("/myConf")
    public Result<List<AssetDramaSyncConf>> getMyConf(@AuthUser SysUser user) {
        List<AssetDramaSyncConf> confList = assetDramaSyncConfService.lambdaQuery().eq(AssetDramaSyncConf::getJobNumber, user.getJobNumber()).list();
        return Result.success(confList, "查询成功");
    }
    
}
