package com.pig4cloud.pig.statistics.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.statistics.api.dto.uninstall.*;
import com.pig4cloud.pig.statistics.api.vo.uninstall.*;
import com.pig4cloud.pig.statistics.service.UninstallAnalyseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: wcl
 * @date: 2025-08-13
 * @description: 流失卸载分析控制器
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/uninstall")
@Tag(description = "uninstall", name = "流失卸载分析")
public class UninstallAnalyseController {

	private final UninstallAnalyseService uninstallAnalyseService;

	@PostMapping("/trend")
	@Operation(summary = "流失概况")
	public R<UninstallTrendVO> getUninstallTrend(@RequestBody GetUninstallTrendDTO dto) {
		return R.ok(uninstallAnalyseService.getUninstallTrend(dto));
	}

	@PostMapping("/trend/detail")
	@Operation(summary = "获取卸载趋势明细数据")
	public R<Page<UninstallTrendDtlVO>> getUninstallTrendDetail(@RequestBody GetUninstallTrendDetailDTO dto) {
		return R.ok(uninstallAnalyseService.getUninstallTrendDetail(dto));
	}

	@PostMapping("/active")
	@Operation(summary = "卸载洞察-卸载设备活跃情况")
	public R<UninstallInsightVO> getActive(@RequestBody GetUninstallInsightDTO dto)  {
		return R.ok(uninstallAnalyseService.getUninstallDeviceActive(dto));
	}

	@PostMapping("/uninstallBefore")
	@Operation(summary = "卸载洞察-卸载前状态")
	public R<UninstallBeforeVO> uninstallBefore(@RequestBody GetUninstallInsightDTO dto) {
		return R.ok(uninstallAnalyseService.uninstallBefore(dto));
	}

	@PostMapping("/uninstallInterfere")
	@Operation(summary = "卸载洞察-体验干扰")
	public R<UninstallBeforeInterfereVO> uninstallInterfere(@RequestBody GetUninstallInsightDTO dto) {
		return R.ok(uninstallAnalyseService.uninstallInterfere(dto));
	}

	@PostMapping("/uninstallAction")
	@Operation(summary = "卸载洞察-行为还原")
	public R<UninstallBeforeActionVO> uninstallAction(@RequestBody GetUninstallInsightDTO dto) {
		return R.ok(uninstallAnalyseService.uninstallAction(dto));
	}

	@PostMapping("/uninstallAfter")
	@Operation(summary = "卸载洞察-卸载后流失")
	public R<List<UninstallOfterAPPOV>> uninstallAfter(@RequestBody GetUninstallInsightDTO dto) {
		return R.ok(uninstallAnalyseService.uninstallAfter(dto));
	}

	@PostMapping("/uninstallSys")
	@Operation(summary = "卸载洞察-设备系统分布")
	public R<List<UninstallSYSOV>> uninstallSys(@RequestBody GetUninstallInsightDTO dto) {
		return R.ok(uninstallAnalyseService.uninstallSys(dto));
	}


	@PostMapping("/portrait")
	@Operation(summary = "卸载画像")
	public R<UninstallPortraitOV> getUninstallPortrait(@RequestBody UninstallPortraitDTO dto) {
		return R.ok(uninstallAnalyseService.getUninstallPortrait(dto));
	}

	@PostMapping("/predict")
	@Operation(summary = "卸载归因-卸载预测")
	public R<List<UninstallPredictVO>> getUninstallPredict(@RequestBody UninstallPredictDTO dto) {
		return R.ok(uninstallAnalyseService.getUninstallPredict(dto));
	}

	@PostMapping("/predict/detail")
	@Operation(summary = "卸载归因-安装卸载比")
	public R<List<InstallUninstallRatioVO>> getInstallUninstallRatio(@RequestBody InstallUninstallRatioDTO dto) {
		return R.ok(uninstallAnalyseService.getInstallUninstallRatio(dto));
	}

	@PostMapping("/predict/detailList")
	@Operation(summary = "卸载归因-安装卸载比明细")
	public R<Page<InstallUninstallRatioVO>> getInstallUninstallRatioDetail(@RequestBody InstallUninstallRatioDTO dto) {
		return R.ok(uninstallAnalyseService.getInstallUninstallRatioDetail(dto));
	}

}
