package com.iqser.red.service.persistence.management.v1.processor.entity.annotations;

import java.io.Serializable;
import java.time.OffsetDateTime;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MapsId;
import jakarta.persistence.Table;

import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "viewed_page")
public class ViewedPageEntity {

    @EmbeddedId
    private ViewedPageId id;
    @Column
    private OffsetDateTime viewedTime;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("fileId")
    private FileEntity file;


    public int getPage() {

        return this.id.page;
    }


    @Data
    @Builder
    @Embeddable
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ViewedPageId implements Serializable {

        @Column(name = "file_id")
        private String fileId;
        @Column
        private int page;
        @Column(name = "user_id")
        private String userId;

    }

}
