package com.czg.controller.admin;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.market.dto.MkBirthdayGiftDTO;
import com.czg.market.service.MkBirthdayGiftService;
import com.czg.market.vo.MkBirthdayGiftRecordSummaryVO;
import com.czg.market.vo.MkBirthdayGiftRecordVO;
import com.czg.market.vo.MkBirthdayGiftVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 生日有礼配置
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/birthdayGift")
public class BirthdayGiftController {
    @Resource
    private MkBirthdayGiftService service;
    /**
     * 记录获取
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "生日有礼",value = "birthdayGift:summary", name = "生日有礼概述")
    @GetMapping("/summary")
    public CzgResult<MkBirthdayGiftRecordSummaryVO> summary(@RequestParam(required = false) String dateTime, @RequestParam(required = false) String key) {
        return CzgResult.success(service.summary(StpKit.USER.getMainShopId(), key, StrUtil.isNotBlank(dateTime) ? DateUtil.parseLocalDateTime(dateTime) : null));
//        return null;
    }

    /**
     * 配置信息获取
     * 权限标识: activate:list
     */
    @SaAdminCheckPermission(parentName = "生日有礼",value = "birthdayGift:detail", name = "生日有礼详情")
    @GetMapping
    public CzgResult<MkBirthdayGiftVO> detail() {
        return CzgResult.success(service.detail(StpKit.USER.getMainShopId()));
    }

    /**
     * 配置信息修改
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "生日有礼",value = "birthdayGift:edit", name = "生日有礼修改")
    @PostMapping
    public CzgResult<Boolean> edit(@Validated @RequestBody MkBirthdayGiftDTO giftDTO) {
        return CzgResult.success(service.edit(StpKit.USER.getMainShopId(), giftDTO));
    }


    /**
     * 记录获取
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "生日有礼",value = "birthdayGift:record", name = "生日有礼记录")
    @GetMapping("/record")
    public CzgResult<Page<MkBirthdayGiftRecordVO>> record(@RequestParam(required = false) LocalDateTime dateTime, @RequestParam(required = false) String key) {
        return CzgResult.success(service.getRecord(StpKit.USER.getMainShopId(), key, dateTime));
    }

}
