package cn.teammodel.repository;

import cn.teammodel.model.entity.ai.ChatApp;
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author winter
 * @create 2023-11-28 17:39
 */
@Repository
public interface ChatAppRepository extends CosmosRepository<ChatApp, String> {
    @Query("SELECT * FROM c WHERE c.code = 'ChatApp' " +
            "AND (IS_NULL(@scope) or c.scope = @scope) " +
            "AND (IS_NULL(@schoolId) or c.schoolId = @schoolId) " +
            "AND (IS_NULL(@creatorId) or c.creatorId = @creatorId) " +
            "AND (IS_NULL(@bizType) or c.bizType = @bizType) " +
            "AND (IS_NULL(@lang) or c.lang = @lang) " +
            "AND (IS_NULL(@itemType) or c.itemType = @itemType) " +
            "AND (IS_NULL(@period) or c.period = @period) " +
            "AND (IS_NULL(@subject) or c.subject = @subject)")
    List<ChatApp> findAllByConditon(String scope,
                                    String schoolId,
                                    String creatorId,
                                    String bizType,
                                    String lang,
                                    String itemType,
                                    String period,
                                    String subject);

    @Query("SELECT c.id, c.schoolId, c.prompt, c.creatorId FROM c WHERE c.code = 'ChatApp' AND c.id = @id")
    List<ChatApp> findByAppId(String id);
}
