package db

import (
	"context"
	"fmt"
	"youngee_b_api/model/gorm_model"
)

func CreateSecTaskLogistics(ctx context.Context, logistics gorm_model.YoungeeTaskLogistics) (*int64, error) {
	db := GetWriteDB(ctx)
	err := db.Create(&logistics).Error
	if err != nil {
		return nil, err
	}

	return &logistics.LogisticsID, nil
}

func UpdateSecTaskLogistics(ctx context.Context, updateData gorm_model.YoungeeTaskLogistics) (*int64, error) {
	db := GetWriteDB(ctx)
	fmt.Println("logistics_id: ", updateData.LogisticsID)
	fmt.Println("updateData: ", updateData)
	err := db.Model(gorm_model.YoungeeTaskLogistics{}).Where("logistics_id", updateData.LogisticsID).Updates(&updateData).Error
	if err != nil {
		return nil, err
	}

	return &updateData.LogisticsID, nil
}

func GetLogistics(ctx context.Context, secTaskId string) (*gorm_model.YoungeeTaskLogistics, error) {
	db := GetWriteDB(ctx)
	logistics := gorm_model.YoungeeTaskLogistics{}
	err := db.Model(gorm_model.YoungeeTaskLogistics{}).Where("task_id", secTaskId).First(&logistics).Error
	if err != nil {
		return nil, err
	}
	return &logistics, nil
}
