package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.store.LifeCoupon;
import shop.alien.mapper.LifeCouponMapper;
import shop.alien.mapper.StoreInfoMapper;

import java.util.Date;

/**
 * 套餐
 */
@Api(tags = {"一期-平台套餐"})
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/pingtaitaocan")
@RequiredArgsConstructor
public class PingtaiTaocanController {

    private final LifeCouponMapper lifeCouponMapper;

    private final StoreInfoMapper storeInfoMapper;


    @GetMapping("getTaocanDetial")
    private LifeCoupon getTaocanList(@RequestParam("id") String id) {
        log.info("LifeCouponController.getTaocanList?id={}", id);
        return lifeCouponMapper.selectById(id);
    }

    @GetMapping("updateTaocanStatus")
    private int updateTaocanStatus(@RequestParam("status") String status,
                                   @RequestParam("id") String id,
                                   @RequestParam("approvalComments") String approvalComments) {
        log.info("LifeCouponController.updateTaocanStatus?status={}&id={}&approvalComments={}", status, id, approvalComments);
        LambdaUpdateWrapper<LifeCoupon> wrapper = new LambdaUpdateWrapper();
        Date now = new Date();
        int ret = 0;
        if (status.equals("0")) {
            wrapper.set(LifeCoupon::getStatus, status)
                    .set(LifeCoupon::getApprovalComments, approvalComments)
                    .set(LifeCoupon::getUpdatedTime, now)
                    .eq(LifeCoupon::getId, id);
            ret = lifeCouponMapper.update(null, wrapper);
            return ret;
        } else if (status.equals("-2")) {
            wrapper.set(LifeCoupon::getStatus, status)
                    .set(LifeCoupon::getApprovalComments, approvalComments)
                    .set(LifeCoupon::getUpdatedTime, now)
                    .eq(LifeCoupon::getId, id);
            ret = lifeCouponMapper.update(null, wrapper);
        }
        return ret;
    }
}
