-- Copyright 2026 Biglup Labs
-- SPDX-License-Identifier: Apache-2.0
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
{-# LANGUAGE OverloadedStrings #-}

-- | Named protocol network magics. These are full 32-bit values, distinct from
-- the four-bit Shelley address tag in "Cometa.NetworkId". Custom networks can
-- use any 'Word32'; these constants do not select a provider or a network endpoint.
module Cometa.NetworkMagic (mainnet, preprod, preview, sanchonet, name) where

-- IMPORTS --------------------------------------------------------------------

import Data.Text (Text)
import Data.Word (Word32)

-- DEFINITIONS ----------------------------------------------------------------

-- | Cardano mainnet protocol magic, 764824073.
mainnet :: Word32
mainnet :: Word32
mainnet = Word32
764824073

-- | Preprod protocol magic, 1.
preprod :: Word32
preprod :: Word32
preprod = Word32
1

-- | Preview protocol magic, 2.
preview :: Word32
preview :: Word32
preview = Word32
2

-- | SanchoNet protocol magic, 4. A protocol identifier does not imply that a
-- hosted endpoint is currently available.
sanchonet :: Word32
sanchonet :: Word32
sanchonet = Word32
4

-- | Lowercase name for the four known magics, or @"unknown"@ for any other
-- value. Custom magic numbers remain valid even when they have no known name.
name :: Word32 -> Text
name :: Word32 -> Text
name Word32
value
  | Word32
value Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
mainnet = Text
"mainnet"
  | Word32
value Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
preprod = Text
"preprod"
  | Word32
value Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
preview = Text
"preview"
  | Word32
value Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
sanchonet = Text
"sanchonet"
  | Bool
otherwise = Text
"unknown"