package com.sonic.frog.controller.api;

import com.sonic.common.rpc.Result;
import com.sonic.frog.domain.input.GetRandomLockImageInput;
import com.sonic.frog.domain.input.UseUserCreateCountInput;
import com.sonic.frog.service.AiUserAlbumService;
import com.sonic.frog.service.UserCreateCountStatService;
import com.sonic.frog.lib.output.AIUserAlbumApiOutput;
import com.sonic.sdk.api.annotation.IgnoreAuth;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.InvalidKeyException;

/**
 * AI接口
 *
 * @author code
 */
@RestController
@Slf4j
public class AiUserAlbumApi {

    @Autowired
    private AiUserAlbumService aiUserAlbumService;
    @Autowired
    private UserCreateCountStatService userCreateCountStatService;

    @IgnoreAuth
    @ApiOperation(value = "获取未解锁的图片", tags = {"API-接口"})
    @PostMapping("/api/ai-user-album/random-lock-image")
    public Result<AIUserAlbumApiOutput> getRandomLockImage(@RequestBody GetRandomLockImageInput input) throws InvalidKeyException {
        return Result.success(aiUserAlbumService.getRandomLockImage(input));
    }

    @IgnoreAuth
    @ApiOperation(value = "编辑形象或创建相册图片时，使用创作次数", tags = {"API-接口"})
    @PostMapping("/api/ai-user-album/use-create-count")
    public Result<Void> useUserCreateCount(@RequestBody UseUserCreateCountInput input) throws InvalidKeyException {
        userCreateCountStatService.useUserCreateCount(input.getUserId());
        return Result.success();
    }
}

