package com.competition.modules.pub.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.competition.modules.ugc.entity.UgcTag;
import com.competition.modules.ugc.mapper.UgcTagMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class PublicTagService {

    private final UgcTagMapper ugcTagMapper;

    /**
     * 获取所有启用标签
     */
    public List<UgcTag> listTags() {
        return ugcTagMapper.selectList(
                new LambdaQueryWrapper<UgcTag>()
                        .eq(UgcTag::getStatus, "enabled")
                        .orderByAsc(UgcTag::getSort));
    }

    /**
     * 获取热门标签
     */
    public List<UgcTag> getHotTags() {
        return ugcTagMapper.selectList(
                new LambdaQueryWrapper<UgcTag>()
                        .eq(UgcTag::getStatus, "enabled")
                        .orderByDesc(UgcTag::getUsageCount)
                        .last("LIMIT 20"));
    }
}
