package com.seer.teach.mall.good.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.DecryptionAnnotation;
import com.seer.teach.common.annotation.EncryptionAnnotation;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.mall.request.SpecificationPageReq;
import com.seer.teach.mall.request.SpecificationSaveReq;
import com.seer.teach.mall.request.SpecificationUpdateReq;
import com.seer.teach.mall.response.SpecificationPageResp;
import com.seer.teach.mall.response.SpecificationResp;
import com.seer.teach.mall.good.service.IAdminSpecificationService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 规格表 前端控制器
 * </p>
 *
 * @author Captain
 * @since 2025-06-10
 */
@RestController
@RequestMapping("/mall/specification")
@Tag(name = "管理端 - 商品规格管理")
@Validated
@RequiredArgsConstructor
public class AdminSpecificationController {

    private final IAdminSpecificationService specificationService;

    @PostMapping("/list")
    @LogPrint
    @Operation(summary = "商品规格分页查询")
    @EncryptionAnnotation
    @DecryptionAnnotation
    @SaCheckPermission("admin:specification:list")
    public ResultBean<PageListBean<SpecificationPageResp>> getSpecificationPage(@RequestBody @Validated SpecificationPageReq params){
        PageListBean<SpecificationPageResp> result = specificationService.getSpecificationPage(params);
        return ResultBean.success(result);
    }

    @PostMapping("/save")
    @LogPrint
    @Operation(summary = "新增商品规格")
    @EncryptionAnnotation
    @DecryptionAnnotation
    @SaCheckPermission("admin:specification:save")
    public ResultBean saveSpecification(@RequestBody @Validated SpecificationSaveReq params){
        specificationService.saveSpecification(params);
        return ResultBean.success();
    }

    @GetMapping("/info/{id}")
    @LogPrint
    @Operation(summary = "根据id查询商品规格信息")
    @EncryptionAnnotation
    @DecryptionAnnotation
    @SaCheckPermission("admin:specification:info")
    public ResultBean<SpecificationResp> getSpecificationInfo(@PathVariable Integer id){
        SpecificationResp specificationInfo = specificationService.getSpecificationInfo(id);
        return ResultBean.success(specificationInfo);
    }

    @PutMapping("/update")
    @LogPrint
    @Operation(summary = "修改商品规格信息")
    @EncryptionAnnotation
    @DecryptionAnnotation
    @SaCheckPermission("admin:specification:update")
    public ResultBean updateSpecification(@RequestBody @Validated SpecificationUpdateReq params){
        specificationService.updateSpcification(params);
        return ResultBean.success();
    }

    @DeleteMapping("/delete")
    @LogPrint
    @Operation(summary = "删除商品规格信息")
    @EncryptionAnnotation
    @DecryptionAnnotation
    @SaCheckPermission("admin:specification:delete")
    public ResultBean deleteSpecification(@RequestBody @Validated @NotNull(message = "id不可为空") List<Integer> ids){
        specificationService.deleteSpecification(ids);
        return ResultBean.success();
    }

    @GetMapping("/queryAll")
    @LogPrint
    @Operation(summary = "查看所有商品规格列表")
    @EncryptionAnnotation
    @DecryptionAnnotation
    @SaCheckPermission("admin:specification:queryAll")
    public ResultBean<List<SpecificationResp>> listSpecification(){
        List<SpecificationResp> results = specificationService.listSpecification();
        return ResultBean.success(results);
    }

}
