// Package controller -----------------------------
// @file      : artwork.go
// @author    : JJXu
// @contact   : wavingbear@163.com
// @time      : 2023/2/24 18:12
// -------------------------------------------
package controller

import (
	"context"
	"errors"
	"github.com/fonchain/fonchain-artistinfo/cmd/internal/logic"
	"github.com/fonchain/fonchain-artistinfo/pb/artistInfoArtwork"
	emptypb "google.golang.org/protobuf/types/known/emptypb"
)

var _ artistInfoArtwork.ArtistInfoArtworkServer = new(ArtistInfoArtworkProvider)

type ArtistInfoArtworkProvider struct {
	artistInfoArtwork.UnimplementedArtistInfoArtworkServer
	artistInfoLogic logic.ArtistInfoArtworkLogic
}

// 进入画作补充信息的流程
func (a ArtistInfoArtworkProvider) GenerateArtworkSupplementInfo(ctx context.Context, request *artistInfoArtwork.ArtworkUidsRequest) (*emptypb.Empty, error) {
	return a.artistInfoLogic.GenerateArtworkSupplementInfo(request)
}

// 画作基本信息是否可编辑
func (a ArtistInfoArtworkProvider) CheckArtworkBaseInfoEditable(ctx context.Context, request *artistInfoArtwork.ArtworkUidRequest) (*artistInfoArtwork.CheckArtworkEditableResponse, error) {
	if request.ArtworkUid == "" {
		return nil, errors.New("ArtworkUid 不能为空")
	}
	return a.artistInfoLogic.CheckArtworkEditable(request, 2)
}

// 画作补充信息是否可编辑
func (a ArtistInfoArtworkProvider) CheckArtworkSupplementInfoEditable(ctx context.Context, request *artistInfoArtwork.ArtworkUidRequest) (*artistInfoArtwork.CheckArtworkEditableResponse, error) {
	if request.ArtworkUid == "" {
		return nil, errors.New("ArtworkUid 不能为空")
	}
	return a.artistInfoLogic.CheckArtworkEditable(request, 3)
}

// 更新画作审批状态
func (a ArtistInfoArtworkProvider) UpdateArtworkAuditStatus(ctx context.Context, request *artistInfoArtwork.UpdateArtworkAuditStatusRequest) (*artistInfoArtwork.ArtworkCommonNoParams, error) {
	if request.FlowIndex != 2 && request.FlowIndex != 3 {
		return nil, errors.New("FlowIndex 不能为空")
	}
	return a.artistInfoLogic.UpdateArtworkAuditStatus(request)
}

func (a ArtistInfoArtworkProvider) GetArtworkLockDetail(ctx context.Context, request *artistInfoArtwork.GetArtworkLockDetailRequest) (*artistInfoArtwork.ArtistLockInfo, error) {
	return a.artistInfoLogic.GetArtworkLockDetail(request)
}

// CreateArtworkLockRecord 创建画作锁定记录
func (a ArtistInfoArtworkProvider) CreateArtworkLockRecord(ctx context.Context, req *artistInfoArtwork.CreateArtworkLockRecordReq) (*artistInfoArtwork.ArtworkCommonNoParams, error) {
	if req.ArtworkUid == "" || req.ArtistUid == "" {
		return nil, errors.New("参数错误")
	}
	return a.artistInfoLogic.CreateArtworkLockRecord(req)
}

// ArtworkLockAction 修改画作锁状态
func (a ArtistInfoArtworkProvider) ArtworkLockAction(ctx context.Context, request *artistInfoArtwork.ArtworkLockActionRequest) (*artistInfoArtwork.ArtworkCommonNoParams, error) {
	return a.artistInfoLogic.ArtworkLockAction(request)
}

// DeleteArtworkRecord 删除话走锁记录
func (a ArtistInfoArtworkProvider) DeleteArtworkRecord(ctx context.Context, request *artistInfoArtwork.DeleteArtworkRecordRequest) (*artistInfoArtwork.ArtworkCommonNoParams, error) {
	return a.artistInfoLogic.DeleteArtworkRecord(request)
}

// GetArtworkRecordUids 获取画作锁记录
func (a ArtistInfoArtworkProvider) GetArtworkLockRecords(ctx context.Context, request *artistInfoArtwork.GetArtworkLockRecordsRequest) (*artistInfoArtwork.ArtworkLockList, error) {
	return a.artistInfoLogic.GetArtworkLockRecords(request)
}

// GetArtworkLockHistoryGroup 查询画作历史记录，按照锁定时间分组
func (a ArtistInfoArtworkProvider) GetArtworkLockHistoryGroup(ctx context.Context, request *artistInfoArtwork.GetArtworkLockHistoryRequest) (*artistInfoArtwork.GetArtworkLockHistoryResponse, error) {
	return a.artistInfoLogic.GetArtworkLockHistoryGroup(request)
}
