package cn.gov.customs.demo.government.controller;

import cn.gov.customs.cacp.enhance.workflow.controller.BaseWorkflowController;
import cn.gov.customs.cacp.enhance.workflow.pojo.runtime.RuntimeOgu;
import cn.gov.customs.cacp.enhance.workflow.pojo.runtime.RuntimeTask;
import cn.gov.customs.cacp.enhance.workflow.runtime.WorkflowRuntimeContext;
import cn.gov.customs.cacp.enhance.workflow.service.ProcessRuntimeService;
import cn.gov.customs.cacp.sdks.core.config.CacpAppProperties;
import cn.gov.customs.cacp.sdks.core.result.Result;
import cn.gov.customs.cacp.sdks.core.user.annotation.LogonUser;
import cn.gov.customs.cacp.sdks.core.user.pojo.CacpLogonUser;
import cn.gov.customs.cacp.sdks.hgid.HgidGenerator;
import cn.gov.customs.demo.government.pojo.GovernmentInfo;
import cn.gov.customs.demo.government.pojo.GovernmentQueryInfo;
import cn.gov.customs.demo.government.pojo.UserTaskQueryInfo;
import cn.gov.customs.demo.government.service.GovernmentService;
import cn.gov.customs.demo.government.service.GovernmentWorkflowEngineService;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author sunxuewen
 * @since 2024/8/15 11:39
 */
@RestController
@RequestMapping("/government")
public class GovernmentController extends BaseWorkflowController<GovernmentInfo> {

  public GovernmentController(CacpAppProperties appProperties, HgidGenerator idHelper, GovernmentService formService, ProcessRuntimeService runtimeService, GovernmentWorkflowEngineService engineService) {
    super(appProperties, idHelper, formService, runtimeService, engineService);
  }

  @GetMapping("/get")
  public Result<GovernmentInfo> get(@RequestParam String formId) {
    String appCode = this.appProperties.getAuthAppCode();
    GovernmentInfo info = this.formService.get(appCode, formId);
    return Result.success(info);
  }

  @PostMapping("/get-page-list")
  public Result<PageInfo<GovernmentInfo>> getPageList(@RequestBody GovernmentQueryInfo query) {
    GovernmentService service = (GovernmentService) this.formService;
    PageInfo<GovernmentInfo> result = service.getPageList(query);
    return Result.success(result);
  }

  @PostMapping("/get-user-task-list-by-page")
  public Result<PageInfo<RuntimeTask>> getUserTaskListByPage(@RequestBody UserTaskQueryInfo query, @LogonUser CacpLogonUser logonUser) {
    String appCode = this.appProperties.getAppCode();
    RuntimeOgu user = RuntimeOgu.from(logonUser);
    GovernmentService service = (GovernmentService) this.formService;
    PageInfo<RuntimeTask> result =  service.getUserTaskListByPage(appCode, user.getParentId(), user.getOguId(), query);
    return Result.success(result);
  }

  @Override
  protected void innerBeforeCreate(GovernmentInfo info, WorkflowRuntimeContext context) {

  }

  @Override
  protected void innerAfterCreate(GovernmentInfo info, WorkflowRuntimeContext context) {

  }

  @Override
  protected void innerAfterStart(GovernmentInfo info, WorkflowRuntimeContext context, Map<String, Object> fields) {

  }

  @Override
  protected void innerAfterSave(GovernmentInfo info, WorkflowRuntimeContext context) {

  }

  @Override
  protected void innerAfterAgree(GovernmentInfo info, boolean status, WorkflowRuntimeContext context, Map<String, Object> fields) {

  }

  @Override
  protected void innerAfterBack(GovernmentInfo info, WorkflowRuntimeContext context, Map<String, Object> fields) {

  }

  @Override
  protected void innerAfterRevoke(GovernmentInfo info, WorkflowRuntimeContext context) {

  }

  @Override
  protected void innerAfterReject(GovernmentInfo info, WorkflowRuntimeContext context, Map<String, Object> fields) {

  }

  @Override
  protected void innerAfterSuspend(GovernmentInfo info, WorkflowRuntimeContext context, Map<String, Object> fields) {

  }

  @Override
  protected void innerAfterResume(GovernmentInfo info) {

  }

  @Override
  protected void innerAfterRedistribution(GovernmentInfo info, WorkflowRuntimeContext context) {

  }

  @Override
  protected void innerAfterDelete(GovernmentInfo info) {

  }

}
