package com.tzld.piaoquan.api.controller;

import com.tzld.piaoquan.api.job.GzhReplyVideoRefreshJob;
import com.tzld.piaoquan.api.model.vo.GhDetailVo;
import com.tzld.piaoquan.api.model.vo.GhTypeVo;
import com.tzld.piaoquan.api.model.vo.StrategyStatusVo;
import com.tzld.piaoquan.api.service.GhDetailService;
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
import com.tzld.piaoquan.growth.common.utils.page.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j

@RestController
@RequestMapping("/account")
@CrossOrigin(origins = "*")
public class AccountDetailController {

    @Autowired
    private GhDetailService ghDetailService;
    @Autowired
    private GzhReplyVideoRefreshJob gzhReplyVideoRefreshJob;

    @GetMapping("/getList")
    public CommonResponse<Page<GhDetailVo>> getAccountDetailList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(defaultValue = "20") Integer pageSize,
                                                                 @RequestParam(defaultValue = "") String accountId,
                                                                 @RequestParam(defaultValue = "") String accountName,
                                                                 @RequestParam(required = false) Long videoId) {
        return ghDetailService.getGhDetailList(pageNum, pageSize, accountId, accountName, videoId);
    }

    @PostMapping("/add")
    public CommonResponse<Void> addAccountDetail(@RequestBody GhDetailVo detailVo) {
        return ghDetailService.addGhDetail(detailVo, new HashMap<>());
    }

    @PostMapping("/update")
    public CommonResponse<Void> updateAccountDetail(@RequestBody GhDetailVo detailVo) {
        return ghDetailService.updateDetail(detailVo, new HashMap<>());
    }

    @PostMapping("/delete")
    public CommonResponse<Void> deleteAccountDetail(@RequestBody GhDetailVo detailVo) {
        return ghDetailService.deleteDetail(detailVo.getId());
    }

    @GetMapping("/types")
    public CommonResponse<List<GhTypeVo>> getAllAccountTypes() {
        return CommonResponse.success(Arrays.stream(GhTypeEnum.values())
                .map(ghTypeEnum -> new GhTypeVo(ghTypeEnum.type, ghTypeEnum.name))
                .collect(Collectors.toList()));
    }

    @GetMapping("/strategyStatus")
    public CommonResponse<List<StrategyStatusVo>> getAllStrategyStatus() {
        return CommonResponse.success(Arrays.stream(StrategyStatusEnum.values())
                .map(strategyStatusEnum -> new StrategyStatusVo(strategyStatusEnum.status, strategyStatusEnum.name))
                .collect(Collectors.toList()));
    }

    @GetMapping("/job/gzhReplyVideoRefreshJob")
    public CommonResponse<Void> gzhReplyVideoRefreshJob() {
        gzhReplyVideoRefreshJob.gzhReplyVideoRefreshJob(null);
        return CommonResponse.success();
    }

    @GetMapping("/job/syncGzhAutoreplyBehaviorUvTotalJob")
    public CommonResponse<Void> syncGzhAutoreplyBehaviorUvTotalJob() {
        gzhReplyVideoRefreshJob.syncGzhAutoreplyBehaviorUvTotalJob(null);
        return CommonResponse.success();
    }
}
