package com.sonic.frog.controller.web;

import com.sonic.common.auth.domains.Session;
import com.sonic.common.rpc.Result;
import com.sonic.frog.domain.input.AiUserImBaseInfoInput;
import com.sonic.frog.domain.input.ClassificationListInput;
import com.sonic.frog.domain.input.HomeRecommendInput;
import com.sonic.frog.domain.output.AiCarouselListOutput;
import com.sonic.frog.domain.output.ClassificationListOutput;
import com.sonic.frog.domain.output.HomeRecommendOutput;
import com.sonic.frog.domain.output.HomeRecommendV2Output;
import com.sonic.frog.service.AdvertiseService;
import com.sonic.frog.service.HomeClassificationService;
import com.sonic.frog.service.HomeRecommendService;
import com.sonic.frog.service.HomeRecommendV2Service;
import com.sonic.sdk.api.annotation.IgnoreAuth;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * Web-首页推荐
 *
 * @author code
 */
@RestController
@Slf4j
public class HomeWeb {

    @Autowired
    private HomeRecommendService homeRecommendService;
    @Autowired
    private HomeClassificationService homeClassificationService;
    @Autowired
    private AdvertiseService advertiseService;
    @Autowired
    private HomeRecommendV2Service homeRecommendV2Service;

    @IgnoreAuth
    @ApiOperation(value = "首页推荐卡片列表", tags = {"Web-首页推荐"})
    @PostMapping("/web/home/rm-list")
    public Result<List<HomeRecommendOutput>> recommendList(@Validated @RequestBody HomeRecommendInput input, @ApiParam(hidden = true) Session session) {
        input.setRandom(true);
        return Result.success(homeRecommendService.recommendList(session.getUserId(), input));
    }

    @IgnoreAuth
    @ApiOperation(value = "获取AI基础信息", tags = {"Web-首页推荐"})
    @PostMapping("/web/home/meet-detail")
    public Result<HomeRecommendOutput> getAiMeetDetail(@Validated @RequestBody AiUserImBaseInfoInput input, @ApiParam(hidden = true) Session session) {
        return Result.success(homeRecommendService.getAiMeetDetail(session.getUserId(), input.getAiId()));
    }

    @IgnoreAuth
    @ApiOperation(value = "首页分类列表", tags = {"Web-首页推荐"})
    @PostMapping("/web/home/classification-list")
    public Result<List<ClassificationListOutput>> classificationList(@Validated @RequestBody ClassificationListInput input, @ApiParam(hidden = true) Session session) {
        return Result.success(homeClassificationService.classificationList(session.getUserId(), input));
    }

    @IgnoreAuth
    @ApiOperation(value = "首页AI轮播列表", tags = {"Web-首页推荐"})
    @PostMapping("/web/home/ai-carousel-list")
    public Result<List<AiCarouselListOutput>> getAiCarouselList(@ApiParam(hidden = true) Session session) {
        return Result.success(advertiseService.getAiCarouselList(session.getUserId()));
    }

    @IgnoreAuth
    @ApiOperation(value = "首页聚合推荐", tags = {"Web-首页推荐"})
    @PostMapping("/web/home/agg-recommend")
    public Result<HomeRecommendV2Output> aggRecommend() {
        log.info("===> LocalDateTime : {}, Date : {}", LocalDateTime.now(), new Date());
        return Result.success(homeRecommendV2Service.recommendList());
    }

}
