package adsrepository

import (
	"errors"
	"fmt"
	adsdomain "legalgo-BE-go/internal/domain/ads"

	"gorm.io/gorm"
)

func (a *accessor) Delete(id string) error {
	var ads adsdomain.Ads
	if err := a.db.First(&ads, "id = ?", id).Error; err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return fmt.Errorf("ads with id %s is not found", id)

		}
		return fmt.Errorf("failed to g ads %s : %v", id, err)
	}

	if err := a.db.Delete(&ads).Error; err != nil {
		return fmt.Errorf("failed to delete ads %s : %v", id, err)
	}

	return nil
}
