package com.ruoyi.web.controller.portal;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SysApplicationCase;
import com.ruoyi.system.service.ISysApplicationCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Anonymous
@RestController
@RequestMapping("/portal/application")
public class PortalApplicationController extends BaseController {

    @Autowired
    private ISysApplicationCaseService applicationCaseService;

    @GetMapping("/list")
    public TableDataInfo getApplicationList(SysApplicationCase applicationCase) {
        startPage();
        List<SysApplicationCase> list = applicationCaseService.selectSysApplicationCaseList(applicationCase);
        return getDataTable(list);
    }

    @GetMapping("/demos")
    public TableDataInfo getDemoList(SysApplicationCase applicationCase) {
        startPage();
        List<SysApplicationCase> list = applicationCaseService.selectSysApplicationCaseList(applicationCase);
        return getDataTable(list);
    }

    @GetMapping("/{id}")
    public AjaxResult getApplicationDetail(@PathVariable("id") Long id) {
        SysApplicationCase applicationCase = applicationCaseService.selectSysApplicationCaseById(id);
        return AjaxResult.success(applicationCase);
    }

    @GetMapping("/stats")
    public AjaxResult getApplicationStats() {
        Map<String, Object> stats = new HashMap<>();
        stats.put("cases", 50);
        stats.put("demos", 20);
        stats.put("areas", 30);
        stats.put("beneficiaries", 1000);
        return AjaxResult.success(stats);
    }

    @GetMapping("/impact")
    public AjaxResult getImpactList() {
        Map<String, Object> impactData = new HashMap<>();
        impactData.put("climate", "30%");
        impactData.put("ecology", "20%");
        impactData.put("agriculture", "15%");
        impactData.put("health", "25%");
        return AjaxResult.success(impactData);
    }
}
