package com.erp.systemtool.entity;

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

import java.time.LocalDateTime;

/**
 * Pull Record Entity
 * 
 * Records order/product pull operations from third-party platforms.
 * Used for tracking sync history and data cleanup.
 */
@Data
@Entity
@Table(name = "pull_records", indexes = {
    @Index(name = "idx_platform", columnList = "platform"),
    @Index(name = "idx_created_at", columnList = "created_at"),
    @Index(name = "idx_tenant_status", columnList = "tenant_id, status")
})
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PullRecord {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "tenant_id")
    private Integer tenantId;

    @Column(name = "platform", length = 32)
    private String platform;

    @Column(name = "pull_type", length = 32)
    private String pullType;

    @Column(name = "status", length = 32)
    private String status;

    @Column(name = "start_time")
    private LocalDateTime startTime;

    @Column(name = "end_time")
    private LocalDateTime endTime;

    @Column(name = "total_count")
    private Integer totalCount;

    @Column(name = "success_count")
    private Integer successCount;

    @Column(name = "fail_count")
    private Integer failCount;

    @Column(name = "error_message", length = 1024)
    private String errorMessage;

    @Column(name = "request_params", columnDefinition = "TEXT")
    private String requestParams;

    @Column(name = "created_at")
    private LocalDateTime createdAt;

    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
    }
}
