using AC2RE.Definitions;

namespace LandblockExtraction.DatEngine {
    public class PortalEngine {
        private readonly DataId TERRAINDESCID = new DataId(0x12000000);
        private readonly DataId SURFACEDESCID = new DataId(0x13000000);
        private readonly DataId LANDSCAPEID = new DataId(0x36000000);

        private DatReader portalReader;

        public CTerrainDesc cTerrainDesc { get; private set; }
        public CSurfaceDesc cSurfaceDesc { get; private set; }
        public LandScapeDefs landScapeDefs { get; private set; }

        public PortalEngine() {
            portalReader = new(@"X:\DatFiles\portal.dat");
            InitTerrainDesc();
            InitSurfaceDesc();
            InitLandScapeDesc();
        }

        public bool InitTerrainDesc() {
            if (!portalReader.contains(TERRAINDESCID)) return false;
            using (var data = portalReader.getFileReader(TERRAINDESCID)) {
                if (data == null) return false;
                cTerrainDesc = new(data);
            }
            return true;
        }
        public bool InitSurfaceDesc() {
            if (!portalReader.contains(SURFACEDESCID)) return false;
            using (var data = portalReader.getFileReader(SURFACEDESCID)) {
                if (data == null) return false;
                cSurfaceDesc = new(data);
            }
            return true;
        }
        public bool InitLandScapeDesc() {
            if (!portalReader.contains(LANDSCAPEID)) return false;
            using (var data = portalReader.getFileReader(LANDSCAPEID)) {
                if (data == null) return false;
                landScapeDefs = new(data);
            }
            return true;
        }
    }
}
