from entity.SrtFileEntity import Srtfile
from common.Utils import getSession
from sqlalchemy import update


class SrtFileService:
    def checkExistsByVideoId(videoid):
        session = getSession()
        srtFile: Srtfile = session.query(Srtfile).filter(
            Srtfile.videoId == videoid).first()
        session.close()
        if srtFile is not None:
            return True
        else:
            return False

    def insertOne(videoId, channelId, ordinal, srtStartTime, srtEndTime, srtText, isScan):
        session = getSession()
        srtFile: Srtfile = Srtfile(videoId=videoId, channelId=channelId, ordinal=ordinal, srtStartTime=srtStartTime,
                                   srtEndTime=srtEndTime, srtText=srtText, isScan=isScan)
        session.add(srtFile)
        session.commit()
        session.close()

    def insertList(srtFiles):
        session = getSession()
        session.bulk_save_objects(srtFiles)
        session.commit()
        session.close()