package models import ( "github.com/sujit-baniya/fiber-boilerplate/app" "gorm.io/gorm" ) // OcrConfig almacena la conexión al servicio propio de OCR (extracción de // texto de imágenes, ej. comprobantes de pago). Solo un registro activo a // la vez, mismo patrón que HostingerConfig/WebSmsConfig. type OcrConfig struct { gorm.Model BaseURL string `json:"base_url" gorm:"column:base_url;type:text;not null"` // ej: https://ocr.u-s.app/extract Token string `json:"token" gorm:"column:token;type:text;not null"` // Bearer token Notas string `json:"notas" gorm:"column:notas;type:text"` Activo bool `json:"activo" gorm:"column:activo;default:true"` } func (OcrConfig) TableName() string { return "ocr_config" } func GetOcrConfig() (*OcrConfig, error) { var item OcrConfig if err := app.Http.Database.DB.Where("activo = ?", true).Order("id DESC").First(&item).Error; err != nil { return nil, err } return &item, nil } func SaveOcrConfig(s OcrConfig) error { app.Http.Database.DB.Model(&OcrConfig{}).Where("activo = ?", true).Update("activo", false) s.Activo = true if s.ID > 0 { return app.Http.Database.DB.Model(&s).Updates(map[string]interface{}{ "base_url": s.BaseURL, "token": s.Token, "notas": s.Notas, "activo": true, }).Error } return app.Http.Database.DB.Create(&s).Error }