package com.red.circle.other.adapter.app.pet;

import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.common.business.dto.PageQueryCmd;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd;
import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.framework.web.controller.BaseController;
import com.red.circle.other.app.dto.clientobject.pet.PetCurrentFeedingCO;
import com.red.circle.other.app.dto.clientobject.pet.PetLibraryCO;
import com.red.circle.other.app.dto.clientobject.pet.PetLibraryDetailsCO;
import com.red.circle.other.app.dto.clientobject.pet.PetOperationLogCO;
import com.red.circle.other.app.dto.clientobject.pet.PetUserFriendCO;
import com.red.circle.other.app.dto.clientobject.sys.PrizeContentCO;
import com.red.circle.other.app.dto.cmd.pet.PetCurrentFeedingCmd;
import com.red.circle.other.app.dto.cmd.pet.PetOperationLogQueryCmd;
import com.red.circle.other.app.service.pet.PetHallService;
import com.red.circle.other.app.service.pet.PetLibraryService;
import com.red.circle.other.infra.database.cache.service.other.ActivityLotteryConfCacheService;
import com.red.circle.other.inner.model.cmd.activity.lottery.ActivityLotteryTurntableCache;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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;

/**
 * 宠物服务.
 *
 * @author lisizhe on 2023/9/19
 * @eo.api-type http
 * @eo.groupName 宠物服务
 * @eo.path /pet
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/pet", produces = MediaType.APPLICATION_JSON_VALUE)
public class PetRestController extends BaseController {

  private final PetHallService petHallService;
  private final PetLibraryService petLibraryService;
  private final ActivityLotteryConfCacheService activityLotteryConfCacheService;

  /**
   * 宠物库分页列表.
   *
   * @eo.name 宠物库分页列表
   * @eo.url /library/page
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/library/page")
  public PageResult<PetLibraryCO> pageLibrary(@Validated PageQueryCmd cmd) {
    return petLibraryService.pageLibrary(cmd);
  }

  /**
   * 宠物库详情.
   *
   * @eo.name 宠物库详情
   * @eo.url /library/details
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/library/details")
  public PetLibraryDetailsCO getLibraryDetails(@Validated AppIdLongCmd cmd) {
    return petLibraryService.getLibraryDetails(cmd);
  }

  /**
   * 激活宠物.
   *
   * @eo.name 激活宠物
   * @eo.url /library/activation
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/library/activation")
  public void activation(@Validated AppIdLongCmd cmd) {
    petLibraryService.activation(cmd);
  }

  /**
   * 当前饲养宠物.
   *
   * @eo.name 当前饲养宠物
   * @eo.url /current
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/current")
  public PetCurrentFeedingCO getCurrentFeeding(AppUserIdCmd cmd) {
    return petHallService.getCurrentFeeding(cmd);
  }

  /**
   * 喂食.
   *
   * @eo.name 喂食
   * @eo.url /feeding
   * @eo.method post
   * @eo.request-type json
   */
  @PostMapping("/feeding")
  public Boolean feeding(@RequestBody @Validated PetCurrentFeedingCmd cmd) {
    return petHallService.feeding(cmd);
  }

  /**
   * 好友列表.
   *
   * @eo.name 好友列表
   * @eo.url /friend
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/friend")
  public List<PetUserFriendCO> listPetFriend(@Validated AppUserIdCmd cmd) {
    return petHallService.listPetFriend(cmd);
  }

  /**
   * 收益.
   *
   * @eo.name 收益
   * @eo.url /receive/income
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/receive/income")
  public void receiveIncome(@Validated AppIdLongCmd cmd) {
    petHallService.receiveIncome(cmd);
  }

  /**
   * 领取养成奖励.
   *
   * @eo.name 领取养成奖励
   * @eo.url /receive/finish/award
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/receive/finish/award")
  public void receiveFinishAward(@Validated AppIdLongCmd cmd) {
    petHallService.receiveFinishAward(cmd);
  }

  /**
   * 宠物流水查询.
   *
   * @eo.name 宠物流水查询
   * @eo.url /running/water
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/running/water")
  public List<PetOperationLogCO> flowRunningWater(@Validated PetOperationLogQueryCmd cmd) {
    return petHallService.flowRunningWater(cmd);
  }

  /**
   * 获取转盘数据.
   *
   * @eo.name 当前饲养宠物
   * @eo.url /turntable
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/turntable")
  public ActivityLotteryTurntableCache turntable(@Validated AppExtCommand cmd) {
    return activityLotteryConfCacheService.getLotteryTurntable(
        SysOriginPlatformEnum.valueOf(cmd.getReqSysOrigin().getOrigin()));
  }

  /**
   * 抽奖.
   *
   * @eo.name 抽奖
   * @eo.url /turntable/lottery
   * @eo.method get
   * @eo.request-type formdata
   */
  @GetMapping("/turntable/lottery")
  public PrizeContentCO turntableLottery(@Validated AppExtCommand cmd) {
    return petHallService.turntableLottery(cmd);
  }

}
