package com.za.room.db.order

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.za.base.Const
import com.za.bean.db.order.PhotoTemplateInfo

@Dao
interface PhotoTemplateDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE, entity = PhotoTemplateInfo::class)
    fun insert(photoTemplateInfo: PhotoTemplateInfo)

    //获取当前节点的图片模板
    @Query("select * from photo_template_bean where myCustomPhotoType=${Const.PhotoType.InServicing}")
    fun getAll(): List<PhotoTemplateInfo>?

    //获取当前节点的图片模板
    @Query("select * from photo_template_bean where taskNode =:taskNode and userOrderId=:userOrderId " +
            "and myCustomPhotoType=${Const.PhotoType.InServicing}")
    fun getOrderPhotoTemplateFromTaskNode(taskNode: Int, userOrderId: Int): List<PhotoTemplateInfo>?

    //获取当前节点的图片模板
    @Query("select * from photo_template_bean where taskNode =:taskNode and taskId=:taskId " +
            "and myCustomPhotoType=${Const.PhotoType.InServicing}")
    fun getOrderPhotoTemplateFromTaskNodeAndTaskId(taskNode: Int, taskId: Int): List<PhotoTemplateInfo>?

    //获取当前节点的图片模板
    @Query("select * from photo_template_bean where userOrderId =:userOrderId " +
            "and myCustomPhotoType=${Const.PhotoType.InServicing}")
    fun queryCurrentOrderHasTaskNode(userOrderId: Int): List<PhotoTemplateInfo>?

    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun update(photoTemplateInfo: PhotoTemplateInfo)

    @Query("delete from photo_template_bean where myCustomPhotoType=${Const.PhotoType.InServicing}")
    fun deleteAllPhotoTemplate()

    @Query("delete from photo_template_bean where taskId =:taskId and myCustomPhotoType=${Const.PhotoType.InServicing}")
    fun deleteOrderPhotoTemplateFromTaskId(taskId: Int)
}