/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;

import static de.srsoftware.umbrella.core.constants.Field.TOKEN;

import de.srsoftware.tools.SessionToken;
import de.srsoftware.umbrella.core.AddableMap;
import java.util.UUID;

public class Token implements CharSequence{

	private final String token;

	public Token(){
		token = UUID.randomUUID().toString();
	}

	private Token(String value){
		this.token = value;
	}

	public String asBearer() {
		return "Bearer "+token;
	}

	public AddableMap asMap(){
		return new AddableMap().plus(TOKEN,token);
	}

	@Override
	public char charAt(int i) {
		return token.charAt(i);
	}

	public static Token of(String val){
		return new Token(val);
	}

	public static Token of(SessionToken sessionToken) {
		return new Token(sessionToken.sessionId());
	}


	@Override
	public int length() {
		return token.length();
	}


	@Override
	public CharSequence subSequence(int start, int end) {
		return token.subSequence(start,end);
	}

	@Override
	public String toString() {
		return token;
	}
}
