package com.czg.controller.admin;

import com.czg.account.dto.PageDTO;
import com.czg.account.dto.register.MerchantRegisterDTO;
import com.czg.account.entity.MerchantRegister;
import com.czg.account.service.MerchantRegisterService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaAdminCheckRole;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 激活码管理
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/merchantRegister")
public class MerchantRegisterController {
    @Resource
    private MerchantRegisterService merchantRegisterService;


    /**
     * 激活码列表
     * 权限标识: merchantRegister:list
     * @param pageDTO   分页参数
     * @param state     状态 0未激活 1已激活
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return 激活码列表
     */
    @SaAdminCheckRole("管理员")
    @SaAdminCheckPermission(parentName = "激活码", value = "merchantRegister:list", name = "激活码列表")
    @GetMapping
    public CzgResult<Page<MerchantRegister>> get(PageDTO pageDTO, Integer state, String startTime, String endTime) {
        return CzgResult.success(merchantRegisterService.get(pageDTO, state, startTime, endTime));
    }

    /**
     * 生成激活码
     * 权限标识: merchantRegister:add
     * @param merchantRegisterDTO 激活码信息
     * @return 是否成功
     */
    @SaAdminCheckRole("管理员")
    @SaAdminCheckPermission(parentName = "激活码", value = "merchantRegister:add", name = "生成激活码")
    @PostMapping
    public CzgResult<Boolean> add(@RequestBody @Validated MerchantRegisterDTO merchantRegisterDTO) {
        return CzgResult.success(merchantRegisterService.add(merchantRegisterDTO));
    }
}
