package de.cannamanage.domain.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;
import java.util.UUID;

/**
 * Stores custom mail domain configuration for Enterprise tier clubs.
 * Verified via DNS TXT record: cannamanage-verify={verification_token}
 */
@Data
@NoArgsConstructor
@Entity
@Table(name = "custom_mail_domains")
public class CustomMailDomain {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private UUID id;

    @Column(name = "tenant_id", nullable = false, unique = true)
    private UUID tenantId;

    @Column(name = "from_address", nullable = false)
    private String fromAddress;

    @Column(name = "domain", nullable = false)
    private String domain;

    @Column(name = "verification_token", nullable = false, length = 64)
    private String verificationToken;

    @Column(name = "verified", nullable = false)
    private boolean verified = false;

    @Column(name = "verified_at")
    private Instant verifiedAt;

    @Column(name = "created_at", nullable = false)
    private Instant createdAt = Instant.now();

    public CustomMailDomain(UUID tenantId, String fromAddress, String domain, String verificationToken) {
        this.tenantId = tenantId;
        this.fromAddress = fromAddress;
        this.domain = domain;
        this.verificationToken = verificationToken;
    }
}
