package com.cool.store.controller.webc;

import com.cool.store.context.PartnerUserHolder;
import com.cool.store.dto.TallyBookDTO;
import com.cool.store.request.TallyBookRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.response.TallyBookDetailResponse;
import com.cool.store.service.TallyBookService;
import com.cool.store.vo.PartnerUserInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: WangShuo
 * @Date: 2025/03/31/14:23
 * @Version 1.0
 * @注释:
 */
@RestController
@Api("mini记账本")
@RequestMapping("/mini/tallyBook")
public class TallyBookController {
    @Resource
    private TallyBookService tallyBookService;

    @PostMapping("/insertOrUpdate")
    @ApiOperation(value = "新增或修改记账本")
    public ResponseResult insertOrUpdateSelective(@RequestBody @Validated TallyBookRequest request) {
        PartnerUserInfoVO user = PartnerUserHolder.getUser();
        request.setOperatorName(user.getUsername());
        return ResponseResult.success(tallyBookService.insertOrUpdateSelective(request, user));
    }

    @GetMapping("/getTallyBookListByShopIdAndYear")
    @ApiOperation(value = "根据店铺id和年份查询记账本")
    public ResponseResult<List<TallyBookDTO>> getTallyBookListByShopIdAndYear(@RequestParam("shopId") Long shopId, @RequestParam("year") Integer year) {
        PartnerUserInfoVO user = PartnerUserHolder.getUser();
        return ResponseResult.success(tallyBookService.getTallyBookListByShopIdAndYear(shopId,year));
    }

    @GetMapping("/getDetail")
    @ApiOperation(value = "查询明细")
    public ResponseResult<TallyBookDetailResponse> getTallyBookDetailByTallyBookId(@RequestParam("tallyBookId") Long tallyBookId) {
        PartnerUserInfoVO user = PartnerUserHolder.getUser();
        return ResponseResult.success(tallyBookService.getTallyBookDetailByTallyBookId(tallyBookId));
    }

}
