use crate::prelude::*;

use super::{ProgramHeaderFlagSet, ProgramHeaderType};

/// the elf64 Program Header.
#[derive(Clone, Default)]
pub struct Elf64ProgramHeader {
    /// segment type
    pub header_type: ProgramHeaderType,
    /// segment flags
    pub flags: ProgramHeaderFlagSet,
    /// segment file offset
    pub offset: Elf64Off,
    /// segment virtual address
    pub vaddr: Elf64Addr,
    /// segment size in file
    pub paddr: Elf64Addr,
    /// segment size in memory
    pub filesz: Elf64Xword,
    /// segment flags
    pub memsz: Elf64Xword,
    /// segment alignment
    pub align: Elf64Xword,
}

impl From<RawElf64ProgramHeader> for Elf64ProgramHeader {
    fn from(value: RawElf64ProgramHeader) -> Self {
        Self {
            header_type: ProgramHeaderType::from(value.p_type),
            flags: ProgramHeaderFlagSet::from(value.p_flags),
            offset: value.p_offset,
            vaddr: value.p_vaddr,
            paddr: value.p_paddr,
            filesz: value.p_filesz,
            memsz: value.p_memsz,
            align: value.p_align,
        }
    }
}

/// the raw representation of the 64-bit Program Header.
#[derive(Clone, Default, Debug)]
pub struct RawElf64ProgramHeader {
    /// segment type
    pub p_type: Elf64Word,
    /// segment flags
    pub p_flags: Elf64Word,
    /// segment file offset
    pub p_offset: Elf64Off,
    /// segment virtual address
    pub p_vaddr: Elf64Addr,
    /// segment size in file
    pub p_paddr: Elf64Addr,
    /// segment size in memory
    pub p_filesz: Elf64Xword,
    /// segment flags
    pub p_memsz: Elf64Xword,
    /// segment alignment
    pub p_align: Elf64Xword,
}
